#include "nec_fs/file_reader.hpp"

nec_fs::FileReader::FileReader(const char *filename) {
  f = fopen(filename, "a");
  fclose(f);
  f = fopen(filename, "r+");
}

int nec_fs::FileReader::ReadStr(std::string &line) {
  bool end_line_flag = false;
  while (!end_line_flag) {
    char ch = fgetc(f);
    if (ch == EOF) {
      return -1;
    }
    if (ch == END_OF_LINE) {
      end_line_flag = true;
    }
    line.push_back(ch);
  }
  return 0;
}

nec_fs::FileReader::~FileReader() {
  if (f != nullptr) {
    fclose(f);
  }
}

